﻿/// <reference name="MicrosoftAjax.js"/>

Type.registerNamespace("YUIAspNet");

YUIAspNet.Paginator = function(element) {
    YUIAspNet.Paginator.initializeBase(this, [element]);
}

YUIAspNet.Paginator.prototype = {
    initialize: function() {
        YUIAspNet.Paginator.callBaseMethod(this, 'initialize');
    },

    initializeYUIControl: function(sender, args) {
        var config =
        {
            rowsPerPage: this.get_RowsPerPage(),
            totalRecords: this.get_TotalRecords(),
            containers: this.get_Containers()
        };

        if (this.get_Template())
            config.template = this.get_Template();

        /*
        blic Dictionary<int, string> RowsPerPageOptions { get; set; }

     

            */
        if (this.get_FirstPageLinkText())
            config.firstPageLinkLabel = this.get_FirstPageLinkText();
        if (this.get_LastPageLinkText())
            config.lastPageLinkLabel = this.get_LastPageLinkText();
        if (this.get_NextPageLinkText())
            config.nextPageLinkLabel = this.get_NextPageLinkText();
        if (this.get_PreviousPageLinkText())
            config.previousPageLinkLabel = this.get_PreviousPageLinkText();
        if(this.get_PageReportTemplate())
            config.pageReportTemplate = this.get_PageReportTemplate();
        if(this.get_PageLinks() >0)
            config.pageLinks = this.get_PageLinks();
        
        this._yuiControl = new YAHOO.widget.Paginator(config);

        var handler = false;
        if (this._events && this._events.getHandler("OnPageChange")) {
            var me = this;
            handler = this._events.getHandler("OnPageChange");
            this._yuiControl.subscribe('changeRequest',
                function(newState) { handler(me, newState); });
        }

        this._yuiControl.render();

        if (handler) // execute for first page
            handler(this, this._yuiControl.getState());
    },

    get_PageLinks: function() {
        return this._pageLinks;
    },
    set_PageLinks: function(pageLinks) {
        this._pageLinks = pageLinks;
    },

    get_RowsPerPage: function() {
        return this._rowsPerPage;
    },
    set_RowsPerPage: function(rowsPerPage) {
        this._rowsPerPage = rowsPerPage;
    },

    get_TotalRecords: function() {
        return this._totalRecords;
    },
    set_TotalRecords: function(totalRecords) {
        this._totalRecords = totalRecords;
    },

    get_PageReportTemplate: function() {
        return this._pageReportTemplate;
    },
    set_PageReportTemplate: function(pageReportTemplate) {
        this._pageReportTemplate = pageReportTemplate;
    },

    get_Containers: function() {
        return this._containers;
    },
    set_Containers: function(containers) {
        this._containers = containers;
    },

    get_LastPageLinkText: function() {
        return this._lastPageLinkText;
    },
    set_LastPageLinkText: function(lastPageLinkText) {
        this._lastPageLinkText = lastPageLinkText;
    },

    get_NextPageLinkText: function() {
        return this._nextPageLinkText;
    },
    set_NextPageLinkText: function(nextPageLinkText) {
        this._nextPageLinkText = nextPageLinkText;
    },

    get_PreviousPageLinkText: function() {
        return this._previousPageLinkText;
    },
    set_PreviousPageLinkText: function(previousPageLinkText) {
        this._previousPageLinkText = previousPageLinkText;
    },

    get_FirstPageLinkText: function() {
        return this._firstPageLinkText;
    },
    set_FirstPageLinkText: function(firstPageLinkText) {
        this._firstPageLinkText = firstPageLinkText;
    },

    get_Template: function() {
        return this._template;
    },
    set_Template: function(template) {
        this._template = template;
    },

    get_InitialPage: function() {
        return this._initialPage;
    },
    set_InitialPage: function(initialPage) {
        this._initialPage = initialPage;
    },

    get_AlwaysVisible: function() {
        return this._alwaysVisible;
    },
    set_AlwaysVisible: function(alwaysVisible) {
        this._alwaysVisible = alwaysVisible;
    },

    get_RecordOffset: function() {
        return this._recordOffset;
    },
    set_RecordOffset: function(recordOffset) {
        this._recordOffset = recordOffset;
    },

    get_UpdateOnChange: function() {
        return this._updateOnChange;
    },
    set_UpdateOnChange: function(updateOnChange) {
        this._updateOnChange = updateOnChange;
    },

    add_OnPageChange: function(handler) {
        this.get_events().addHandler("OnPageChange", handler);
    },
    remove_OnPageChange: function(handler) {
        this.get_events().removeHandler("OnPageChange", handler);
    }

    //FirstPageLink - << first ->previousPageLinkLabel
    //LastPageLink - last >>
    //PreviousPageLink - < prev
    //NextPageLink - next >
    //PageLinks - 1 2 3 4 5
    //CurrentPageReport - (1 of 21)
    //RowsPerPageDropdown - { value : NUMBER, text : STRING }
    //pageLinks
    //rowsPerPageOptions 
    //pageReportTemplate

    //firstPageLinkLabel
    //lastPageLinkLabel
    //previousPageLinkLabel
    //nextPageLinkLabel
    //8	} 
    //},



}

YUIAspNet.Paginator.registerClass('YUIAspNet.Paginator', YUIAspNet.BaseControl);
